home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / PlainTalk™ Speech Technologies / Text To Speech / Programming Stuff / Examples / WannaSpeech / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-15  |  6.0 KB  |  202 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file is where you place various definitions and constant values for
  20. ** DTS.Lib..framework's use.  You will also add some code within the two
  21. ** functions to handle the various document types. */
  22.  
  23. /**************************************************************************************
  24. WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 
  25.  
  26. Changes have been made to the pristine purity of this code I have added the lines
  27. necessary to change it from AppWannaBe to WannaSpeech, the Text to Speech sample
  28. from AppleSoft Developer Technical Support
  29.  
  30.    Written by:    Guillermo A. Ortiz        AppleSoft Developer Technical Support
  31.    Date:        08/04/93
  32.  
  33. Please read WannaSpeech.readme for the gruesome details.
  34. **************************************************************************************/
  35. /*****************************************************************************/
  36.  
  37.  
  38.  
  39. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  40. #include "App.defs.h"        /* Get various application definitions.            */
  41. #include "App.protos.h"        /* Get the prototypes for application.            */
  42. #include "WannaSpeech.h"
  43.  
  44. #ifndef __ERRORS__
  45. #include <Errors.h>
  46. #endif
  47.  
  48. #ifndef __UTILITIES__
  49. #include "Utilities.h"
  50. #endif
  51.  
  52. /* In this file, we first set some global values.  This allows the application and
  53. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  54.  
  55.  
  56. short        gTypeListLen = 1;
  57. SFTypeList    gTypeList = {kDocFileType};
  58.     /* Here we declare the various document types that Wannabe can support.
  59.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  60.  
  61.  
  62.  
  63. /* Some DTS.Lib..framework gTypeList usage notes:
  64. **
  65. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  66. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  67. **     The index at which the match is found (+1) is used as the string number in the
  68. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  69. **     resource, then the last string is used.
  70. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  71. **     can be selected. */
  72.  
  73.  
  74.  
  75. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  76.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  77.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  78.     TheDoc            doc;            /* will place on the end of each.                            */
  79. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  80.  
  81.  
  82.  
  83. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  84. ** application.  The first 16 are reserved for the framework.  Our application-specific
  85. ** objects start at 16. */
  86.  
  87. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  88. /* 1  */                                         TRootObj,
  89. /* 2  */                                         TUndoObj,
  90. /* 3  */                                         TUndoTaskObj,
  91. /* 4  */                                         TUndoPartObj,
  92. /* 5  */                                         nil,
  93. /* 6  */                                         nil,
  94. /* 7  */                                         nil,
  95. /* 8  */                                         nil,
  96. /* 9  */                                         nil,
  97. /* 10 */                                         nil,
  98. /* 11 */                                         nil,
  99. /* 12 */                                         nil,
  100. /* 13 */                                         nil,
  101. /* 14 */                                         nil,
  102. /* 15 */                                         nil};
  103. /* 16 Start of app-specific procs. */
  104.  
  105.  
  106.  
  107. /* The framework needs to know the minimum object sizes.  This table is used by the
  108. ** framework to make sure that the object is created at least minimally. */
  109.  
  110. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  111. /* 1  */                                         sizeof(RootObj),
  112. /* 2  */                                         sizeof(UndoObj),
  113. /* 3  */                                         sizeof(UndoTaskObj),
  114. /* 4  */                                         sizeof(UndoPartObj),
  115. /* 5  */                                         0,
  116. /* 6  */                                         0,
  117. /* 7  */                                         0,
  118. /* 8  */                                         0,
  119. /* 9  */                                         0,
  120. /* 10 */                                         0,
  121. /* 11 */                                         0,
  122. /* 12 */                                         0,
  123. /* 13 */                                         0,
  124. /* 14 */                                         0,
  125. /* 15 */                                         0};
  126. /* 16 Start of app-specific sizes. */
  127.  
  128.  
  129.  
  130. /*****************************************************************************/
  131. /*****************************************************************************/
  132.  
  133.  
  134.  
  135. /* •• Called by DTS.Lib..framework. •• */
  136.  
  137. /* Do any additional document initialization here.  All fields not specifically set
  138. ** are already initialized to 0. */
  139.  
  140. #pragma segment File
  141. OSErr    InitDocument(FileRecHndl frHndl)
  142. {
  143.     OSErr    err;
  144.  
  145.     err = noErr;
  146.  
  147.     switch ((*frHndl)->fileState.sfType) {
  148.         case kDocFileType:
  149.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  150.             if (!err) {
  151.                 /* Additional document initialization having to do with speech. */
  152.                 InitDocSpeech(frHndl);
  153.             }
  154.             break;
  155. #if VH_VERSION
  156.         case kViewHierFileType:
  157.             return(VHInitDocument(frHndl));
  158.             break;
  159. #endif
  160.         default:
  161.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  162.             if (!err) {
  163.                 (*frHndl)->fileState.readDocumentProc  = nil;
  164.                 (*frHndl)->fileState.writeDocumentProc = nil;
  165.             }
  166.             break;
  167.     }
  168.  
  169.     return(err);
  170. }
  171.  
  172.  
  173.  
  174. /*****************************************************************************/
  175.  
  176.  
  177.  
  178. /* •• Called by DTS.Lib..framework. •• */
  179.  
  180. /* Return the initial size of the primary document handle, based on the OSType. */
  181.  
  182. #pragma segment File
  183. long    InitDocumentSize(OSType sftype)
  184. {
  185.     switch (sftype) {
  186.         case kDocFileType:
  187.             return(sizeof(DocFileTypeRec));
  188.             break;
  189. #if VH_VERSION
  190.         case kViewHierFileType:
  191.             return(VHFileTypeSize());
  192.             break;
  193. #endif
  194.         default:
  195.             return(sizeof(DocFileTypeRec));
  196.             break;
  197.     }
  198. }
  199.  
  200.  
  201.  
  202.